<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
/**
 +------------------------------------------------------------------------------
 * 客服系统-坐席
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2014-8-13
 +------------------------------------------------------------------------------
 */
namespace Admin\Controller;

class ServiceSeatController extends AdminController {

	/**
	 * @todo 推荐列表
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function recommendList(){
	    $recommend_name = strip_tags(I('recommend_name'));
	    $map = array();
	    $map['status'] = array('gt',-1);
	    if($recommend_name!=''){
	        $map['recommend_name'] = array('like', '%'.(string)$recommend_name.'%');
	    }
	    $map['member_id'] = UID;
	    $list = $this->lists('service_recommend',$map,'recommend_id','recommend_id,recommend_name,status,create_time');
	    $this->assign('list',$list);
	    $this->assign('meta_title','推荐列表管理');
	    $this->display();
	}

	/**
	 * @todo 我的推广客户列表
	 * @author mahuan <mahuan@1768.com>
	 */
	public function myPromoteCustomer(){
	    $this->assign('meta_title','我的推广列表');
	    //获取活动列表
	    $activity_list = D('ServiceApi')->getServiceActivity('1,2,3,4');
	    if(false === $activity_list){
	    	$this->error('获取活动列表出错');
	    }
	    $this->assign('activity_list',$activity_list);
	    $map = array();
		$activity_id = (int)I('activity_id');
	    if($activity_id != 0){
	    	$map['activity_id'] = $activity_id;
	    }
	    $phone = trim(I('phone'));
	    if($phone){
	    	if (!preg_match("/^1[3-8][0-9]{9}$/",$phone)) {
	    		$this->error('电话号码输入错误。');
	   		}
	   		$customer = D('Admin/Customer','Service')->getCustomerIdByMobilePhone($phone);
	    	if($customer['status'] == 1){
	        	$map['customer_id'] = (int)$customer['data']['customer_id'];
	        }else{
	        	$this->error('没有找到用户！');
	        }
	    }
	    //如果两项目都没选，则提示输入条件
	    if($activity_id == 0 && empty($phone)){
	    	$this->assign('_list',null);
	    	$this->assign('info_txt','请选择活动或输入电话号！');
	    	$this->display();
	    	return false;
	    }
	    //只显示正常的
	    $map['status'] = 1;
	    $map['is_valid'] = 0;
	    $map['generalize_member_id'] = UID;
		$list = $this->lists('ServiceActivityJoin',$map,'customer_id','customer_id,generalize_member_id,activity_id');
		if(false === $list){
			$this->error('查找用户错误。');
		}
		$this->assign('_list',$list);
	    $this->display();
	}
	
	/**
	 * @todo 查找我的老用户
	 * @author fang
	 * @since 2015-9-4
	 */
	public function queryCustomer(){
	    $phone = strip_tags(I('phone'));
	    if($phone){
	        if(!preg_match('/^1[3-8][0-9]{9}$/', $phone)){
	            $this->error('电话号码输入错误');
	        }
            $customer = D('Admin/Customer','Service')->getCustomerIdByMobilePhone($phone);
            if($customer['status'] == 1){
                $map['customer_id'] =  (int)$customer['data']['customer_id'];
            }
	    }
	    $map['member_id'] = UID;
	    $list = $this->lists(D('ServiceMyCustomerView'),$map,'call_time asc,create_time desc,customer_id desc');
	    Cookie('__next_call_customer_param__',$_GET); // 用于呼叫页面（查询下一个用户的参数）
	    $this->assign('_list',$list);
    	$this->assign('meta_title','我的老客户');
	    $this->display();
	}


	/**
	 * @todo 推荐管理
	 * @author PHP@妖孽 <dino_ma@163.com>
	 * @since 2015-9-4
	 */
	public function recommend(){
		if(IS_POST){
			$activity_list = (array)I('post.activity_list');//活动信息二维数组
			$village_list = (array)I('post.village');//小区信息 一维数组
			$demand_content_list = (array)I('post.demand_content_id');//需求内容信息 一维数组, KEY为键名
			$min_decoration_meter = (int)I('post.min_decoration_meter');//最小平米数
			$max_decoration_meter = (int)I('post.max_decoration_meter');//最小平米数
			$min_decoration_budget = doubleval(I('post.min_decoration_budget'));//最少装修预算
			$max_decoration_budget = doubleval(I('post.max_decoration_budget'));//最 多装修预算
			$min_home_time = strtotime(I('post.min_home_time'));//最快进户时间
			$max_home_time = strtotime(I('post.max_home_time'));//最慢进户时间
			$min_decoration_time = strtotime(I('post.min_decoration_time'));//最快装修时间
			$max_decoration_time = strtotime(I('post.max_decoration_time'));//最慢装修时间
			//房产装修信息
			$house_info = array(
					'min_decoration_meter'=>$min_decoration_meter,
					'max_decoration_meter'=>$max_decoration_meter,
					'min_decoration_budget'=>$min_decoration_budget,
					'max_decoration_budget'=>$max_decoration_budget,
					'min_home_time'=>$min_home_time,
					'max_home_time'=>$max_home_time,
					'min_decoration_time'=>$min_decoration_time,
					'max_decoration_time'=>$max_decoration_time
			);
			$call_back = D('ServiceRecommend')->getRecommendList($activity_list,$village_list,$demand_content_list,$house_info);
			if($call_back['status']==1){
				$this->ajaxReturn($call_back);
			}else{
				$this->error($call_back['info']);
			}
		}else{
			$this->assign('activity_list',D('ServiceApi')->getServiceActivity(4));
			$this->assign('meta_title','推荐管理');
			$this->display('recommend');
		}
	}
	
	
	/**
	 * @todo 创建我的推荐列表
	 * @author PHP@妖孽<dino_ma@163.com>
	 * @since 2015-9-5
	 */
	public function addNewRecommend(){
		if(IS_POST){
			$recommend_name = trim(I('recommend_name'));
			$customer_ids  = $_POST['list'];
			$call_back = D('ServiceRecommend')->creatMyRecommend($recommend_name,$customer_ids);
			if($call_back['status']==1){
				$this->ajaxReturn($call_back);
			}else{
				$this->error($call_back['info']);
			}
		}else{
			$this->error('你跟我俩心思妹呐?');
		}
	}
	
	
	/**
	 * 删除某一个推荐列表
	 * @author PHP@妖孽  <dino_ma@163.com>
	 */
	public function delRecommend(){
		$ids    =   I('request.ids');
		$status =   I('request.status');
		if(empty($ids)){
			$this->error('请选择要操作的数据');
		}
		$map['recommend_id'] = array('in',$ids);
		if(!empty($ids)){
		    foreach ($ids as $id){
		        action_log('recommend_del', 'service_recommend', $id, UID);
		    }
		}
		$this->delete('service_recommend', $map, array('success'=>'删除成功','error'=>'删除失败'));
		
		
	}

	/**
	 * @todo 我的活动推荐
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-4
	 */
	public function myRecommend(){
	    $recommend_id=(int)I('get.recommend_id');  //推荐id
	    $is_call=(int)I('get.is_call');    //拨打状态 0=未拨打;1=稍后拨打;2=已拨打 
	    
	    //选择推荐列表
	    $field = 'recommend_id,recommend_name';
	    $map = array('member_id'=>UID,'status'=>1);
	    $recommend = M('service_recommend')->field($field)->where($map)->select();
	    $this->assign('recommend',$recommend);
	    $this->assign('meta_title','活动推荐');
        
	    //确定筛选条件
	    if($recommend_id>0 && in_array($is_call,array(0,1))){
	        if($is_call==0){//未拨打
	            $where=array('recommend_id'=>$recommend_id,'is_valid'=>0,'is_call'=>$is_call);
	            $order='customer_id asc';
	        }else{//稍后拨打
	            $where=array('recommend_id'=>$recommend_id,'is_valid'=>0,'is_call'=>$is_call,'member_id'=>UID);
	            $order='later_call_time asc';
	        }
    	    $list=$this->lists('service_recommend_customer',$where,$order,'customer_id,later_call_time');
	    }else{
	        $list=null;
	        $this->assign('_page',null);
	    }
	    Cookie('__next_call_customer_param__',$_GET); // 用于呼叫页面（查询下一个用户的参数）
	    $this->assign('_list',$list);
        $this->display();
	}

	/**
	 * @todo 我的名单
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-4
	 */
	public function myRollCall(){
	    $type=(int)I('get.type'); //显示类型 1=名单;2=稍后拨打
	    switch ($type){
	        case 1: //获取我的名单
	            $roll_call_id=D('ServiceApi')->getServiceMemberRollCallList(UID);
	            if(!empty($roll_call_id)){
	                $roll_call_id = array_column($roll_call_id, 'roll_call_id');
	                $map['roll_call_id'] = array('in',$roll_call_id);
	                $map['status'] = 1 ;
	                $list = $this->lists('service_roll_call',$map,'','roll_call_id,roll_call_name');
	            }else{
	                $list = null;
	                $this->assign('_page',null);
	            }
	            break;
	        case 2: //获取稍后拨打客户
	            $map['is_call'] = 1;
	            $map['is_bind'] = 0;
	            $map['hold_member_id'] = UID;
	            $map['is_valid'] = 0;
                $list = $this->lists('service_roll_call_customer',$map,'later_call_time asc','customer_id,later_call_time');
	            break;
	        default:
                $list=null;
                $this->assign('_page',null);
	    }
	    
	    Cookie('__next_call_customer_param__',$_GET); // 用于呼叫页面（查询下一个用户的参数）
	    $this->assign('_list',$list);
        $this->assign('meta_title','名单拨打');
	    $this->display();
	}

	/**
	 * @todo 门票确认提醒
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-5
	 */
	public function ticketConfirmation(){
        $activity_id = (int)I('get.activity_id');   //活动id
        $ticket_level = (int)I('get.ticket_level','-1');    //票别 0=普通票; 1=VIP; -1=全部
        $sign_channel = (int)I('get.sign_channel','-1');    //报名渠道  0=主动报名;1=票点报名;2=代报名;3=活动现场报名;4=推广报名
        $is_call = (int)I('get.is_call');  //拨打状态 0=未拨打;1=稍后拨打;2=已拨打 
        $sort = (int)I('get.sort','-1');   //排序  0=正序;1=倒序

        if($activity_id > 0){
            $map['activity_id'] = $activity_id;
            if(in_array($sign_channel, array(0,1,2,3,4))) $map['sign_channel'] = $sign_channel;
            if(in_array($ticket_level, array(0,1))) $map['ticket_level'] = $ticket_level;
            $map['member_id'] = UID;
            $map['is_valid'] = 0;
            if(in_array($is_call, array(0,1,2))) $map['is_call'] = $is_call;
            
            //如果通话记录是稍后拨打或者是已拨打状态时 才有按时间的排序
            switch ($is_call){
                case 0:
                    $order = 'activity_join_id';
                    break;
                case 1:
                    $order = 'later_call_time';
                    break;
                case 2:
                    $order = 'last_call_time';
                    break;
                default:
                    $order = 'activity_join_id';
            }
            if($sort==0 && !empty($order)){
                $order .= ' asc';
            }
            if($sort==1 && !empty($order)){
                $order .= ' desc';
            }
            
            $list=$this->lists(D('ServiceActivityJoinView'),$map,$order);
            int_to_string($list,array('sign_channel'=>array('0'=>'主动报名','1'=>'网点报名','2'=>'代报名','3'=>'活动现场报名',4=>'推广报名')));
        }else{
            $list = null;
            $this->assign('_page',null);
        }
        $this->assign('_list',$list);
        
        //正在推荐的活动
        $activity=D('ServiceApi')->getServiceActivity('1');
        if(empty($activity)){
            $activity=null;
        }
	    $this->assign('activity',$activity);
	    Cookie('__next_call_customer_param__',$_GET); // 用于呼叫页面（查询下一个用户的参数）
	    $this->assign('meta_title','门票确认提醒');
	    $this->display();
	}

	/**
	 * @todo 活动回访
     * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-5
	 */
	public function activityVisit(){
	    $activity_id = (int)I('get.activity_id');   //活动id
	    $ticket_level = (int)I('get.ticket_level','-1');    //票别 0=普通票; 1=VIP; -1=全部
	    $sign_channel = (int)I('get.sign_channel','-1');    //报名渠道  0=主动报名;1=票点报名;2=代报名;3=活动现场报名;4=推广报名
	    $is_call = (int)I('get.is_call');  //拨打状态 0=未拨打;1=稍后拨打;2=已拨打
	    $sort = (int)I('get.sort','-1');   //排序  0=正序;1=倒序
	    $is_signin = (int)I('get.is_signin','-1'); //签到  0=未签到;1=签到;-1=全部
	    $is_order = (int)I('get.is_order','-1');   //订单  0=未签单;1=签单;-1=全部
	    
	    if($activity_id > 0){
	        $map['activity_id'] = $activity_id;
	        if(in_array($sign_channel, array(0,1,2,3,4))) $map['sign_channel']=$sign_channel;
	        if(in_array($ticket_level, array(0,1))) $map['ticket_level']=$ticket_level;
	        $map['member_id'] = UID;
	        $map['is_valid'] = 0;
	        if(in_array($is_call, array(0,1,2))) $map['is_call'] = $is_call;
	        if(in_array($is_signin, array(0,1))) $map['is_signin'] = $is_signin;
	        if(in_array($is_order, array(0,1))) $map['is_order'] = $is_order;
	        //如果通话记录是稍后拨打或者是已拨打状态时 才有按时间的排序
            switch ($is_call){
                case 0:
                    $order = 'activity_join_id';
                    break;
                case 1:
                    $order = 'later_call_time';
                    break;
                case 2:
                    $order = 'last_call_time';
                    break;
                default:
                    $order = 'activity_join_id';
            }
            if($sort==0 && !empty($order)){
                $order .= ' asc';
            }
            if($sort==1 && !empty($order)){
                $order .= ' desc';
            }
            $list=$this->lists(D('ServiceActivityJoinView'),$map,$order);
	        int_to_string($list,array('sign_channel'=>array('0'=>'主动报名','1'=>'网点报名','2'=>'代报名','3'=>'活动现场报名',4=>'推广报名')));
	    }else{
	        $list = null;
	        $this->assign('_page',null);
	    }
	    $this->assign('_list',$list);
	    
	    //回访中的活动
	    $activity=D('ServiceApi')->getServiceActivity('3');
	    if(empty($activity)){
            $activity=null;
        }
	    $this->assign('activity',$activity);
	    Cookie('__next_call_customer_param__',$_GET); // 用于呼叫页面（查询下一个用户的参数）
	    $this->assign('meta_title','活动回访');
	    $this->display();
	}

	/**
	 * @todo 我的老客户 的坐席呼叫页面
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-8
	 */
	public function queryCustomerDial(){
	    $customer_id = (int)I('get.id');   //用户id
	    $origin = (int)I('get.origin');    //来源
	    
	    if($customer_id == 0){
	        $this->error('用户id错误');
	    }
	    
	    if($origin != 6){
	        $this->error('来路有问题，请从列表页进入');
	    }
	    
	    $ServiceSeat = D('ServiceSeat');
	    //验证用户的所有权
	    if(false === $ServiceSeat->getBindMember($customer_id)){
	        $error = $ServiceSeat->getError();
	        $this->error($error['info']);
	    }
	    $ServiceApi = D('ServiceApi');
	    //修改信息
	    if(IS_POST){
	        $submit_type=(int)I('post.submit_type');   //拨打下一个时的类型 1=稍后拨打;2=无效拨打下一个;3=跳过;4=拨打下一个
	        //进入呼叫页面时直接取出要拨打的下一个客户
	        $url = $ServiceSeat->callNext($customer_id,$origin,array());
	        if(false === $url){
	            $this->error($ServiceSeat->getError());
	        }
            
            //从老客户拨打页面过来的用户才走这里
            if($submit_type==2){
                //无效时 先把客服系统用户详细信息 中 置为无效，并清空缓存。
                M('service_customer_detail')->where(array('customer_id'=>$customer_id))->save(array('is_valid'=>1));
                S('service_customer_detail',null);
                $data['status'] = 1;
                $data['info'] = '设置无效成功';
                $data['url'] = $url;
                $this->ajaxReturn($data);
            }
            //nengwan 修改
            session('last_phone', getCustomerName($customer_id));
            $data['status']=1;
            $data['info']='正在跳转...';
            $data['url']=$url;
            $this->ajaxReturn($data);
	    }
	    
        //用户信息--cache
        $customer_detail = $ServiceApi->getServiceCustomerDetail($customer_id);
        if(empty($customer_detail)){
            $this->error("用户不存在");
        }
        $this->assign('customer_detail',$customer_detail);
    
        //装修需求(我的装修需求)
        $demand_value = $ServiceSeat->getCustomerDemand($customer_id);
        $this->assign('demand_value',$demand_value);
    
        //可以推荐的活动--cache
        $activity = $ServiceApi->getServiceActivity('1');
        $this->assign('activity',$activity);
    
        //最后通话时间
        $last_call_time=$ServiceSeat->getLastCallTime($customer_id);
        $this->assign('last_call_time',$last_call_time);
    
        //提交的参数
        $this->assign('param',$_GET);
        $this->assign('c','queryCustomerDial');
        
        $this->assign('meta_title','呼叫页面');
        $this->assign('nav_title','我的老客户');
        $this->assign('nav_url',U('ServiceSeat/queryCustomer'));
        $this->display('call');
	}
	
	/**
	 * @todo 活动推荐 的坐席呼叫页面
	 * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-8
	 */
	public function myRecommendDial(){
	    $customer_id = (int)I('get.id');   //用户id
	    $origin = (int)I('get.origin');    //来源
	    $param = Cookie('__next_call_customer_param__');
	    
	    if($origin != 1){
	        $this->error('来路有问题，请从列表页进入');
	    }
	    
	    if(empty($param)){
	        $this->error('您的页面来路有问题，请从列表页直接访问');
	    }
	    $recommend_id = (int)$param['recommend_id'];
	    
	    $ServiceSeat = D('ServiceSeat');
	    //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
        $ServiceApi = D('ServiceApi');
        
	    //修改信息
	    if(IS_POST){
	        $later_call_time = I('post.later_call_time','','htmlspecialchars'); //稍后拨打的时间
	        $submit_type = (int)I('post.submit_type');   //拨打下一个时的类型 1=稍后拨打;2=无效拨打下一个;3=跳过;4=拨打下一个
            
	        //进入呼叫页面时直接取出要拨打的下一个客户
	        $url = $ServiceSeat->callNext($customer_id,$origin,$param);
	        if(false === $url){
	            $this->error($ServiceSeat->getError());
	        }
	        
            //保存呼叫记录
	        $return = $ServiceSeat->dialLog('service_recommend_customer',$submit_type,$customer_id,$recommend_id,$later_call_time);
	        if(false === $return){
	            $this->error($ServiceSeat->getError());
	        }
	        
            //呼叫状态保存成功后， 新增操作日志
            switch ($submit_type){
                case 1: //稍后拨打，拨打下一个
                    $c = 'myRecommendDialLog_is_later';
                    break;
                case 2: //无效，拨打下一个
                    $c = 'myRecommendDialLog_is_valid';
                    break;
                case 3: //跳过，拨打下一个
                    break;
                case 4: //保存，拨打下一个
                    $c = 'myRecommendDialLog_is_call';
                    break;
            }
            action_log($c, 'ServiceSeat', $customer_id, UID);

	        //nengwan 修改
	        session('last_phone', getCustomerName($customer_id));
	        $data['status']=1;
	        $data['info']='正在跳转...';
	        $data['url']=$url;
	        $this->ajaxReturn($data);
	    }
	    
        //用户信息--cache
        $customer_detail = $ServiceApi->getServiceCustomerDetail($customer_id);
        if(empty($customer_detail)){
            $this->error("用户不存在");
        }
        $this->assign('customer_detail',$customer_detail);

        //装修需求(我的装修需求)
        $demand_value = $ServiceSeat->getCustomerDemand($customer_id);
        $this->assign('demand_value',$demand_value);

        //可以推荐的活动--cache
        $activity = $ServiceApi->getServiceActivity('1');
        $this->assign('activity',$activity);
        
        //最后通话时间
        $last_call_time = $ServiceSeat->getLastCallTime($customer_id);
        $this->assign('last_call_time',$last_call_time);
        
        //提交的参数
        $this->assign('param',$_GET);
        $this->assign('c','myRecommendDial');
        
        $this->assign('meta_title','呼叫页面');
        $this->assign('nav_title','活动推荐');
        $this->assign('nav_url',U('ServiceSeat/myRecommend'));
        $this->display('call');
	}

    /**
     * @todo 名单拨打的坐席呼叫页面
     * @author fzh<fanzhaohai@hrbjjhh.com>
	 * @since 2015-9-8
     */
    public function myRollCallDial(){
        $customer_id = (int)I('get.id');
        $roll_call_id = (int)I('get.roll_call_id');
        $origin = (int)I('get.origin');    //来源
        $param = Cookie('__next_call_customer_param__');
        
        if($origin != 2 && $origin != 3){
            $this->error('来路有问题，请从列表页进入');
        }
        
        if(empty($param)){
            $this->error('您的页面来路有问题，请从列表页直接访问');
        }
        $param['roll_call_id'] = $roll_call_id;
        
        $ServiceSeat = D('ServiceSeat');
	    //如果是名单中过来的用户
        if($roll_call_id > 0){
            //取出一个数据并变为持有
            $customerId=$ServiceSeat->getRollCallCustomerId($roll_call_id);
            if($customerId === false){
                $this->error($ServiceSeat->getError());
            }
            $customer_id = $customerId;
        }
        $url = $ServiceSeat->callNext($customer_id,$origin,$param);
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            //如果已经有绑定人了，需要更改名单中的绑定状态
            if(isset($error['id'])){
                $map=array('customer_id'=>$customer_id);
                $data=array('is_bind'=>1,'hold_member_id'=>0,'bind_member_id'=>$error['id'],'later_call_time'=>0);
                M('service_roll_call_customer')->where($map)->save($data);
            }
            $this->error($error['info']);
        }
        $ServiceApi = D('ServiceApi');
        
        //修改信息
        if(IS_POST){
            $submit_type=(int)I('post.submit_type');
            $customer_id=(int)I('post.customer_id');
            $later_call_time=I('post.later_call_time','','htmlspecialchars');
            $url = $ServiceSeat->callNext($customer_id,$origin,$param);
            if(false === $url){
                $this->error($ServiceSeat->getError());
            }
            
            //保存呼叫记录
            $return = $ServiceSeat->dialLog('service_roll_call_customer',$submit_type,$customer_id,0,$later_call_time);
            if(false === $return){
                $this->error($ServiceSeat->getError());
            }
            
            //呼叫状态保存成功后， 新增操作日志
            switch ($submit_type){
                case 1:
                    $c='myRollCallDialLog_is_later';
                    break;
                case 2:
                    $c='myRollCallDialLog_is_valid';
                    break;
                case 3:
                    break;
                case 4:
                    $c='myRollCallDialLog_is_call';
                    break;
            }
            action_log($c, 'ServiceSeat', $customer_id, UID);

            //nengwan 修改
            session('last_phone', getCustomerName($customer_id));
            $data['status']=1;
            $data['info']='正在跳转...';
            $data['url']=$url;
            $this->ajaxReturn($data);
        }
        //用户信息--cache
        $customer_detail = $ServiceApi->getServiceCustomerDetail($customer_id);
        if(empty($customer_detail)){
            $this->error("用户不存在");
        }
        $this->assign('customer_detail',$customer_detail);

        //装修需求
        $demand_value=$ServiceSeat->getCustomerDemand($customer_id);
        $this->assign('demand_value',$demand_value);

        //可以推荐的活动--cache
        $activity=$ServiceApi->getServiceActivity('1');
        $this->assign('activity',$activity);

        //最后通话时间
        $last_call_time=$ServiceSeat->getLastCallTime($customer_id);
        $this->assign('last_call_time',$last_call_time);
        
        //提交的参数
        $this->assign('param',$_GET);
        $this->assign('c','myRollCallDial');
        
        $this->assign('meta_title','呼叫页面');
        $this->assign('nav_title','名单拨打');
        $this->assign('nav_url',U('ServiceSeat/myRollCall'));
        $this->display('call');
    }

    /**
     * @todo 活动确认提醒的坐席呼叫页面
     * @author fzh<fanzhaohai@hrbjjhh.com>
     * @since 2015-9-8
     */
    public function ticketConfirmationDial(){
        $customer_id=(int)I('get.id');
        $origin = (int)I('get.origin');    //来源
        $param = Cookie('__next_call_customer_param__');
        
        if($origin != 4){
            $this->error('来路有问题，请从列表页进入');
        }
        
        if(empty($param)){
            $this->error('您的页面来路有问题，请从列表页直接访问');
        }
        $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
        $ServiceApi = D('ServiceApi');
        //修改信息
        if(IS_POST){
            $later_call_time = I('post.later_call_time','','htmlspecialchars');
            $submit_type=(int)I('post.submit_type');
            
            //进入呼叫页面时直接取出要拨打的下一个客户
            $url = $ServiceSeat->callNext($customer_id,$origin,$param);
            if(false === $url){
                $this->error($ServiceSeat->getError());
            }
            
            //保存是否呼叫
            $return = $ServiceSeat->dialLog('service_activity_join',$submit_type,$customer_id,0,$later_call_time);
            if(false === $return){
                $this->error($ServiceSeat->getError());
            }
            //呼叫状态保存成功后， 新增操作日志
            switch ($submit_type){
                case 1:
                    $c='ticketConfirmDialLog_is_later';
                    break;
                case 2:
                    $c='ticketConfirmDialLog_is_valid';
                    break;
                case 3:
                    break;
                case 4:
                    $c='ticketConfirmDialLog_is_call';
                    break;
            }
            action_log($c, 'ServiceSeat', $customer_id, UID);
            
            //nengwan 修改
            session('last_phone', getCustomerName($customer_id));
            $data['status']=1;
            $data['info']='正在跳转...';
            $data['url']=$url;
            $this->ajaxReturn($data);
        }
        //用户信息--cache
        $customer_detail = $ServiceApi->getServiceCustomerDetail($customer_id);
        $this->assign('customer_detail',$customer_detail);
        
        //装修需求
        $demand_value=$ServiceSeat->getCustomerDemand($customer_id);
        $this->assign('demand_value',$demand_value);

        //可以推荐的活动--cache
        $activity=$ServiceApi->getServiceActivity('1');
        $this->assign('activity',$activity);

        //最后通话时间
        $last_call_time=$ServiceSeat->getLastCallTime($customer_id);
        $this->assign('last_call_time',$last_call_time);
        
        //提交的参数
        $this->assign('param',$_GET);
        $this->assign('c','ticketConfirmationDial');
        
        $this->assign('meta_title','呼叫页面');
        $this->assign('nav_title','门票确认提醒');
        $this->assign('nav_url',U('ServiceSeat/ticketConfirmation'));
        $this->display('call');
    }

    /**
     * @todo 活动回访的坐席呼叫页面
     * @author fzh<fanzhaohai@hrbjjhh.com>
     * @since 2015-9-8
     */
     public function activityVisitDial(){
         $customer_id=(int)I('get.id');
         $origin = (int)I('get.origin');    //来源
         $param = Cookie('__next_call_customer_param__');
         
         if($origin != 5){
             $this->error('来路有问题，请从列表页进入');
         }
         
         if(empty($param)){
             $this->error('您的页面来路有问题，请从列表页直接访问');
         }
         
         $ServiceSeat = D('ServiceSeat');
         //验证用户的所有权
         if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
         }
	     $ServiceApi = D('ServiceApi');

         //修改信息
         if(IS_POST){
             $submit_type=(int)I('post.submit_type');
             $later_call_time = I('post.later_call_time','','htmlspecialchars');
             
             //进入呼叫页面时直接取出要拨打的下一个客户
             $url = $ServiceSeat->callNext($customer_id,$origin,$param);
             if(false === $url){
                 $this->error($ServiceSeat->getError());
             }
             
             //保存呼叫记录
            $return = $ServiceSeat->dialLog('service_activity_join',$submit_type,$customer_id,0,$later_call_time);
            if(false === $return){
                $this->error($ServiceSeat->getError());
            }
            //呼叫状态保存成功后， 新增操作日志
            switch ($submit_type){
                case 1:
                    $c='activityVisitDialLog_is_later';
                    break;
                case 2:
                    $c='activityVisitDialLog_is_valid';
                    break;
                case 3:
                    break;
                case 4:
                    $c='activityVisitDialLog_is_call';
                    break;
            }
            action_log($c, 'ServiceSeat', $customer_id, UID);
             
             //nengwan 修改
             session('last_phone', getCustomerName($customer_id));

             $data['status']=1;
             $data['info']='正在跳转...';
             $data['url']=$url;
             $this->ajaxReturn($data);
         }
         //用户信息--cache
         $customer_detail = $ServiceApi->getServiceCustomerDetail($customer_id);
         if(empty($customer_detail)){
             $this->error('用户不存在');
         }
         $this->assign('customer_detail',$customer_detail);

         //装修需求
         $demand_value=$ServiceSeat->getCustomerDemand($customer_id);
         $this->assign('demand_value',$demand_value);
        
         //可以推荐的活动--cache
         $activity=$ServiceApi->getServiceActivity('1');
         $this->assign('activity',$activity);

         //最后通话时间
         $last_call_time=$ServiceSeat->getLastCallTime($customer_id);
         $this->assign('last_call_time',$last_call_time);
         
         //提交的参数
         $this->assign('param',$_GET);
         $this->assign('c','activityVisitDial');
         
         $this->assign('meta_title','呼叫页面');
         $this->assign('nav_title','活动回访');
         $this->assign('nav_url',U('ServiceSeat/activityVisit'));
         $this->display('call');
     }

     /**
      * @todo 通过customer_id 获取 报名过名的数据
      * @author fzh<fanzhaohai@hrbjjhh.com>
      * @since 2015-9-8
      */
     public function getHistoryActivity(){
        $customer_id=(int)I('get.id');
        $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
        $ajaxReturn = $ServiceSeat->historyActivity($customer_id);
        $this->ajaxReturn($ajaxReturn);
     }

     /**
      * @todo 通过customer_di 获取操作日志
      * @author fzh<fanzhaohai@hrbjjhh.com>
      * @since 2015-9-8
      */
     public function getOperationLog(){
         $customer_id=(int)I('get.id');
         $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
         $list=$this->lists('service_operation_log',array('customer_id'=>$customer_id),'operation_log_id desc','member_id,remark,create_time');
         $this->assign('_list',$list);
         $this->display('operation_log');
     }

     /**
      * @todo 通过customer_di 获取房产信息
      * @author fzh<fanzhaohai@hrbjjhh.com>
      * @since 2015-9-8
      */
     public function getHouseList(){
         $customer_id=(int)I('get.id');
         $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
         if($customer_id==0){
             $house_list=null;
         }else{
             $house_list=D('ServiceApi')->getServiceCustomerHouse($customer_id);
         }
         $this->assign('house_list',$house_list);
         $this->display('house_list');
     }

     /**
      * @todo 通过customer_id 获取房产信息
      * @author fzh<fanzhaohai@hrbjjhh.com>
      * @since 2015-9-8
      */
     public function saveHouse(){
         $customer_id=(int)I('get.customer_id');
         if($customer_id==0){
             $data['status']=0;
             $data['info']='用户id不存在';
             $this->ajaxReturn($data);
         }
         $ServiceSeat = D('ServiceSeat');
         //验证用户的所有权
         if(false === $ServiceSeat->getBindMember($customer_id)){
             $error = $ServiceSeat->getError();
             $this->error($error['info']);
         }
         
         $obj=D('ServiceCustomerHouse');
         $id=$obj->update();
         if($id!==false){
             S('service_customer_house',null);
             //保存操作日志
             $ServiceApi = D('ServiceApi');
             if(!isset($_POST[$obj->getPk()])){
                 $ServiceApi->operationLog($customer_id,2,'增加房产信息');
                 action_log('customerHouse_add', 'ServiceCustomerHouse', $id, UID);
             }else{
                 $ServiceApi->operationLog($customer_id,4,'修改房产信息');
                 action_log('customerHouse_update', 'ServiceCustomerHouse', $id, UID);
             }
             
             $data['status']=1;
             $data['data']=array('id'=>$id);
             $data['info']='操作成功';
             $this->ajaxReturn($data);
         }else{
             $data['status']=0;
             $data['info']=$obj->getError();
             $this->ajaxReturn($data);
         }
     }

     /**
      * @todo 通过customer_id 获取房产信息
      * @author fzh<fanzhaohai@hrbjjhh.com>
      * @since 2015-9-8
      */
     public function delHouse(){
         $id=(int)I('post.house_id');
         $customer_id=(int)I('get.customer_id');
         if($id==0){
             $data['status']=0;
             $data['info']='参数错误';
             $this->ajaxReturn($data);
         }
         $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
         $customer_house=M('service_customer_house')->where(array('house_id'=>$id))->save(array('status'=>-1));
         if($customer_house){
             S('service_customer_house',null);
             //保存操作日志
             D('ServiceApi')->operationLog($customer_id,3,'删除房产信息');
             action_log('customerHouse_del', 'ServiceCustomerHouse', $id, UID);
             $data['status']=1;
             $data['info']='删除成功';
             $this->ajaxReturn($data);
         }else{
             $data['status']=0;
             $data['info']='删除失败';
             $this->ajaxReturn($data);
         }

     }

    /**
     * @todo  呼叫页面的活动报名
     * @author fzh<fanzhaohai@hrbjjhh.com>
     * @since 2015-9-8
     *
     */
     public function activityJoin(){
         $customer_id=(int)I('get.id');
         $activity_id=(int)I('get.activity_id');
         if($customer_id==0 || $activity_id==0){
             $this->error('参数错误');
             exit();
         }
         $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
         
         //查看活动报名 是否报名
         $activity_info=D('ServiceActivityJoin')->getActivityJoinShow($activity_id,'',$customer_id);
         switch ($activity_info['status']){
             case 0:
                 $this->error($activity_info['info']);
                 break;
             case 1:
                 $activity_data=$activity_info['data'];
                 break;
             case 2:
                 $activity_data=null;
                 break;
             case -1:
                 $this->error($activity_info['info']);
                 break;
         }
         $this->assign('activity_info',$activity_data);

        //报名、转化VIP、或者是修改报名活动信息
        if(IS_POST){
            $phone_number=I('post.phone_number','','htmlspecialchars');
            $ticket_level=I('post.ticket_level','','htmlspecialchars');
            $bus_point_id=(int)I('post.bus_point_id');
            $customer_level=(int)I('post.customer_level');
            $departure_time_id=I('post.departure_time_id','','htmlspecialchars');
            $people_num=I('post.people_num','','htmlspecialchars');
            $phone_number=I('post.phone_number','','htmlspecialchars');

            $serviceSeat=D('ServiceSeat');
            $return=$serviceSeat->addActivityJoin($activity_info,$activity_id,$customer_id,$ticket_level,$departure_time_id,$people_num,$customer_level,$bus_point_id);
            if($return===false){
                $this->error($serviceSeat->getError());
            }else{
                $this->success('报名信息修改成功');
            }
        }

        //快递公司
        $express=M('service_express')->select();
        if(empty($express)){
            $express=null;
        }
        $this->assign('express',$express);

        //VIP邮寄信息
        $expressDetail=D('ServiceApi')->getMemberActivityExpressDetail($activity_id,0,$customer_id);
        $this->assign('expressDetail',$expressDetail);

        //班车信息
        $activityBusList=D('ServiceApi')->getActivityBusList($activity_id);
        $this->assign('activityBusList',$activityBusList);

        //短信模板
        $activitySmsTemplate=D('ServiceApi')->getActivitySmsTemplate($activity_id);
        $this->assign('activitySmsTemplate',$activitySmsTemplate);

        //班车时间
        $activityDepartureTime=D('ServiceApi')->getActivityDepartureTime($activity_id);
        $this->assign('activityDepartureTime',$activityDepartureTime);

        //我选择的班车时间
        $map=array('customer_id'=>$customer_id,'activity_id'=>$activity_id);
        $activity_join_bus_demand=M('service_activity_join_bus_demand')->where($map)->select();
        if(empty($activity_join_bus_demand)){
            $bus_demand=array(
                'bus_point_id'=>'',
                'departure_time_id'=>array(),
                'people_num'=>array()
            );
        }else{
            foreach ($activity_join_bus_demand as $val){
                $bus_demand['bus_point_id']=$val['bus_point_id'];
                $bus_demand['departure_time_id'][]=$val['departure_time_id'];
                $bus_demand['people_num'][$val['departure_time_id']]=$val['people_num'];
            }
        }
        $this->assign('bus_demand',$bus_demand);

        $this->assign('meta_title','活动报名');
        $this->display();
     }

     /**
      * @todo 虚报
      * @author fzh
      * @since 2015-9-10
      */
     public function isFalse(){
         $activity_join_id=(int)I('get.activity_join_id');
         $ServiceSeat=D('ServiceSeat');
         $return = $ServiceSeat->isFalse($activity_join_id);
         if($return === false){
             $this->error($ServiceSeat->getError());
         }else{
             action_log('isFalse', 'ServiceSeat', $activity_join_id, UID);
             $this->success('设置虚报成功');
         }
     }
     
     /**
      * @todo 发动短信 
      * @author fzh
      * @since 2015-9-14
      */
     public function sendSms(){
         $activity_id = (int)I('get.activity_id');
         $customer_id = (int)I('get.customer_id');
         $sms_template_id = (int)I('post.sms_template_id');
         $ServiceSeat = D('ServiceSeat');
        //验证用户的所有权
        if(false === $ServiceSeat->getBindMember($customer_id)){
            $error = $ServiceSeat->getError();
            $this->error($error['info']);
        }
         
         $serviceSmsTemplate = D('ServiceSmsTemplate');
         if($serviceSmsTemplate->sendSms($sms_template_id,$customer_id,$activity_id)===false){
             $this->error($serviceSmsTemplate->getError());
         }else{
             D('ServiceApi')->operationLog($customer_id,6,'发送短息['.getActivityName($activity_id).']['.getSmsTemplateName($sms_template_id).']');
             action_log('sendSms', 'ServiceSeat', $sms_template_id, UID);
             $this->success('发送成功');
         }
         
     }

     /**
      * @todo 保存个人信息
      * @author fzh
      * @since 2015-9-16
      */
     public function saveCustomer(){
         $customer_id = (int)I('post.customer_id');
         $ServiceSeat = D('ServiceSeat');
         //验证用户的所有权
         if(false === $ServiceSeat->getBindMember($customer_id)){
             $error = $ServiceSeat->getError();
             $this->error($error['info']);
         }
         //修改个人信息
         $obj=D('ServiceCustomerDetail');
         $id = $obj->update();
         if(false === $id){
             $this->error($obj->getError());
         }else{
             //清空个人信息缓存
             S('service_customer_detail',null);
             S('sys_service_customer_detail_',null);
             S('sys_customer_new_',null);
             //保存操作日志
             if($id>0){
                D('ServiceApi')->operationLog($customer_id,0,'修改个人信息');
                action_log('customerDetail_update', 'ServiceCustomerDetail', $customer_id, UID);
             }
         }
         
         //修改装修需求
         $demand_content_id=I('post.demand_content_id','','htmlspecialchars');
         D('ServiceSeat')->saveCustomerDemand($customer_id,$demand_content_id);
         $data['status']=1;
         $data['info']='个人信息保存成功';
         $this->ajaxReturn($data);
     }

     
     /**
      * @todo    获取区域下的销售网点（HTML）[公用]
      * @author  fang
      */
     public function getPointList(){

         $province_id = (int)I('province_id');
         $city_id = (int)I('city_id');
         $ward_id = (int)I('ward_id');
         if($province_id == 0 || $city_id == 0 || $ward_id == 0){
             $this->error('区域选择错误');
         }
         $sale_list = D('ServiceApi')->getAreaSalePointList($province_id, $city_id, $ward_id);
         $result = '';
         if($sale_list){
             $result .= '<br>';
             $count = count($sale_list);
             for($i=0;$i<$count;$i++){
                 $result .= '<label class="fl"><input type="radio" class="js_sale_point" name="sale_point_id" style="margin:0 3px 3px 0;" value="'.$sale_list[$i]['sale_point_id'].'" onclick="getActivity('.$sale_list[$i]['sale_point_id'].')"  /> '.$sale_list[$i]['sale_point_name'].'　　</label>' ;
             }
         }else{
             $this->error('该区域下没有销售网点，请重新选择！');
         }
         $this->success($result);
     }

     /**
      * @todo       获取销售网点下的活动（HTML）[公用]
      * @author     fang
      */
     public function getPointActivity(){

         $sale_point_id = (int)I('sale_point_id');
         if($sale_point_id == 0){
             $this->error('销售网点错误');
         }
         $activity = M('service_activity_sale_point')->where(array('sale_point_id' => $sale_point_id))->select();
         if(empty($activity)){
             $this->error('该网点没有活动');
         }
         $activity_ids = array_column($activity, 'activity_id');
         //获取活动
         $where['activity_id'] = array('in', $activity_ids);
         $where['status'] = 1;
         $activity_list = M('service_activity')->field('activity_id,activity_name')->where($where)->select();
         if($activity_list){
             $result = '<div class="filter-turnover filter-group form-inline clearfix"><a class="title">选择活动</a><br>';
             foreach ($activity_list as $key=>$val){
                 $result .= '<label class="radio-group"><input type="radio" name="activity_id" class="js_activity" style="margin:0 3px 3px 0;" value="'.$val['activity_id'].'" > '.$val['activity_name'].'</label>' ;
             }
             $result .= '</div>';
             $this->success($result);
         }else{
             $this->error('该网点没有可推荐活动');
         }


     }

    /**
     * @todo    销售网点报名
     * @author  fang
     */
    public function salePointSignUp(){

        if(IS_POST){
            //参数
            $activity_id = (int)I('activity_id');//活动ID号
            $sign_channel = 1;//1:票点报名;2:代报名;
            $phone_number = strip_tags(I('phone_number'));//手机号
            $customer_name = strip_tags(I('customer_name', ''));//姓名
            $customer_id = 0;
            $ticket_level = (int)I('ticket_level');//0:普通票;1:VIP
            $sale_point_id = (int)I('sale_point_id');//票点id(销售网点id)
            $generalize_member_id = UID;//推广人（员工id)
            $customer_level = 0;
            $bus_point_id = (int)I('bus_point_id');//班车点
            //转化参数
            $ticket_type = (int)I('ticket_type');//1:转化
            $activity_join_id = (int)I('activity_join_id');
            $customer_id = (int)I('customer_id');
            if($sale_point_id == 0){
                $this->error('请选择销售网点');
            }
            if($activity_id == 0){
                $this->error('请选择活动');
            }
            if(empty($phone_number)){
                $this->error('请输入手机号');
            }
            //普通转VIP
            $join_obj = D('ServiceActivityJoin');
            if($ticket_type == 1 && $ticket_level == 1 && $activity_join_id > 0 && $customer_id > 0){
                $change = $join_obj->changeActivityJoin($activity_join_id, 1, 0, $sale_point_id);
                if($change === false){
                    $this->error('VIP转化失败');
                }else{
                    $change_vip = true;
                }
            }else{
                if($customer_id == 0){
                    //报名（普通或VIP）
                    $join = $join_obj->getAddActivityJoin($activity_id, $sign_channel, $phone_number, $customer_id, $ticket_level, $sale_point_id, $generalize_member_id, $customer_level, $customer_name);
                    if($join){
                        action_log('activityJoin_add', 'ServiceActivityJoin', $join['activity_join_id'], UID);
                        $customer_id = (int)$join['customer_id'];
                        $sign_success = true;
                    }else{
                        $join_search = $join_obj->getActivityJoinShow($activity_id, $phone_number, 0 , $customer_name);
                        $customer_id = (int)$join_search['data']['customer_id'];
                    }
                }
                //已报普通修改班车信息
            }
            if($customer_id == 0){
                $this->error('用户信息错误');
            }
            //删除班车信息
            $where = array(
                'activity_id' => $activity_id,
                'customer_id' => $customer_id,
            );
            $bus_obj = M('service_activity_join_bus_demand');
            $demand_delete = $bus_obj->where($where)->delete();
            if($demand_delete === false){
                $this->error($bus_obj->getError());
            }
            //重写班车信息
            if($bus_point_id > 0){
                $departure_time_id = (array)I('departure_time_id');
                $people_num = (array)I('people_num');
                //写入用户班车点和发车时间
                $data = array();
                if($bus_point_id > 0 && $departure_time_id){
                    $count = count($departure_time_id);
                    for ($i=0;$i<$count;$i++){
                        $data[] = array(
                            'activity_id' => $activity_id,
                            'member_id' => (int)UID,
                            'customer_id' => $customer_id,
                            'bus_point_id' => $bus_point_id,
                            'departure_time_id' => (int)$departure_time_id[$i],
                            'people_num' => (int)$people_num[$departure_time_id[$i]][0],
                        );
                    }
                    if($data){
                        $add = $bus_obj->addAll($data);
                        if($add === false){
                            $this->error($bus_obj->getError());
                        }
                        action_log('activityJoinBusDemand_update', 'ServiceSeat', $customer_id, UID);
                    }
                }
            }
            if(isset($change_vip)){
                $this->success('转化成功');
            }
            if(isset($sign_success)){
                $this->success('报名成功');
            }
            $this->error('此用户已报名该票别。');
        }else{
            $this->meta_title = '销售网点报名';
            $this->display();
        }
    }


    /**
     * @todo 获取报名信息
     * @author  fang
     */
    public function getActivitySign(){

        $activity_id = (int)I('activity_id');
        $phone = strip_tags(I('phone'));
        $customer_name = strip_tags(I('customer_name', ''));
        if($activity_id == 0){
            $this->error('活动参数错误');
        }
//         if(!preg_match("/^(13[\d]{9}|15[\d]{9}|17[\d]{9}|18[\d]{9})$/", $phone)){
        if(!preg_match('/^1[3-8][0-9]{9}$/', $phone)){
            $this->error('手机号错误');
        }
        //查看用户是否已经报名
        $bus_array = array();
        $departure_array = array();
        $people_array = array();
        $join = D('ServiceActivityJoin')->getActivityJoinShow($activity_id, $phone, 0, $customer_name);
        if($join['status'] == 1){
            $where['activity_id'] = $join['data']['activity_id'];
            $where['customer_id'] = $join['data']['customer_id'];
            $info = M('service_activity_join_bus_demand')->field('bus_point_id,departure_time_id,people_num')->where($where)->select();
            if($info){
                $bus_array = array_unique(array_column($info, 'bus_point_id'));
                $departure_array = array_column($info, 'departure_time_id');
                $people_array = array_column($info,'people_num','departure_time_id');
            }
        }
        //获取活动下的发车时间
        $api_obj = D('ServiceApi');
        $departure = $api_obj->getActivityDepartureTime($activity_id);
        $departure_html = '';
        if($departure){
            foreach ($departure as $key=>$val){
                $people_value = '';
                $checked = (in_array($val['departure_time_id'], $departure_array))? 'checked' : '' ;
                if(isset($people_array[$val['departure_time_id']])){
                    if((int)$people_array[$val['departure_time_id']] > 0){
                        $people_value = (int)$people_array[$val['departure_time_id']];
                    }
                }
                $departure_html .= '<span class="departure_check" style="line-height:35px;"><label class="checkbox"><input type="checkbox" '.$checked.' name="departure_time_id[]" value="'.$val['departure_time_id'].'" > '.time_format($val['departure_time'], 'Y-m-d').'</label>　乘车人数：<input value="'.$people_value.'" type="text" name="people_num['.$val['departure_time_id'].'][]" maxlength="3" style="width:30px; text-align:center;" onkeyup="value=value.replace(/\D*$/,\'\')" onblur="value=value.replace(/\D*$/,\'\')"/></span><br>';
            }
        }
        //获取活动下的班车点
        $bus = $api_obj->getActivityBusList($activity_id);
        $bus_html = '<option value=0>选择班车</option>';
        $bus_id = 0;
        if($bus){
            foreach ($bus as $key=>$val){
                if(in_array($val['bus_point_id'], $bus_array)){
                    $bus_id = $val['bus_point_id'];
                }
                $bus_html .= "<option value='".$val['bus_point_id']."'>".getBusPointName($val['bus_point_id'])."</optiion>";
            }
        }
        $result = array(
            'status' => 1,
            'join' => $join,
            'departure' => $departure_html,
            'bus' => $bus_html,
            'bus_id' => (int)$bus_id,
        );

        $this->ajaxReturn($result);
    }

	/**
	 * @todo 邮寄门票
	 * @author fang
	 * @since 2015-9-9
	 */
     public function mailingTickets(){

         //参数
         $activity_id = (int)I('activity_id', 0);
         $mail_status = (int)I('mail_status', -2);
         $phone_number = strip_tags(I('phone_number', ''));
         //条件

         $map = array();
         if($activity_id != 0){
             $map['activity_id'] = $activity_id;
         }else if($activity_id == 0 && $mail_status != -2){
             $this->error('请选择活动');
         }
         if($mail_status != -1 && $mail_status != -2){
             $map['mail_status'] = $mail_status;
         }
         if($phone_number){
//              if(!preg_match("/^(13[\d]{9}|15[\d]{9}|17[\d]{9}|18[\d]{9})$/", $phone_number)){
             if(!preg_match('/^1[3-8][0-9]{9}$/', $phone_number)){
                 $this->error('手机号错误');
             }
             $map['receiving_phone_number'] = $phone_number;
         }
         if($map){
             $map['member_id'] = UID;
         }

         $list = ($map)? $this->lists(M('service_express_detail'),$map,'mail_time asc') : null ;

         $activity_list = D('ServiceApi')->getServiceActivity('1,2,3,4');
         $this->meta_title = 'Vip票查看及拒收';
         $this->assign('activity_list',$activity_list);
         $this->assign('_list', $list);
         $this->display();

     }

     /**
      * @todo   Vip报名用户详细
	  * @author fang
	  * @since  2015-9-9
      */
     public function vipInfo(){

         $customer_id = (int)I('customer_id');
         $activity_id = (int)I('activity_id');
         if($customer_id == 0 || $activity_id == 0){
             $this->error('访问参数错误');
         }

         //数据
         $customer = D('ServiceManage')->getServiceCustomerInfo($customer_id);
         $activity = D('ServiceManage')->getServiceActivityInfo($customer_id, $activity_id);

         $this->meta_title = '查看Vip客户信息';
         $this->assign('customer', $customer);
         $this->assign('activity', $activity);
         $this->display('vip_info');

     }

}
